Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add separate accounts for each policy in e2e tests #2459

Merged
merged 5 commits into from
Jul 12, 2024

Conversation

kingpinXD
Copy link
Contributor

@kingpinXD kingpinXD commented Jul 10, 2024

Description

Closes #2447

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Introduced separate policy accounts: emergency, operational, and admin, for more granular control.
  • Refactor

    • Replaced FungibleAdminName with new policy names across tests and configurations.
    • Updated scripts to support newly defined policy accounts.
    • Enhanced end-to-end test configuration to utilize multiple policy accounts.
  • Bug Fixes

    • Fixed issues with transaction broadcasting by using specific policy accounts.
  • Documentation

    • Updated changelog to reflect changes in account handling and policy account introductions.

Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Walkthrough

This change involves refactoring the zeta-chain repository's end-to-end tests to use separate policy accounts for different roles: Emergency, Operational, and Admin, instead of a single FungibleAdmin account. This change ensures better segregation and management of policy-specific actions in tests.

Changes

File(s) Change Summary
changelog.md Summary of changes detailing the addition of separate policy accounts for end-to-end tests in the zeta-chain repository.
cmd/zetae2e/config/localnet.yml Redefined policy accounts with new addresses and private keys while removing the user_fungible_admin account. Added emergency_policy_account, operational_policy_account, and admin_policy_account.
cmd/zetae2e/local/local.go Modified the localE2ETest function to use three different policy names and corresponding raw private key strings from conf.PolicyAccounts instead of utils.FungibleAdminName.
contrib/localnet/scripts/start-zetacored.sh Updated the script to set different policy account addresses and add them as genesis accounts using zetacored add-genesis-account. Updated the genesis file with the corresponding policy addresses.
e2e/config/config.go Added PolicyAccounts struct and updated AdditionalAccounts struct. Added methods to convert PolicyAccounts to a slice and validate policy accounts. Modified Validate function to validate policy accounts alongside additional accounts. Updated GenerateKeys function to generate keys for policy accounts instead of UserFungibleAdmin.
e2e/e2etests/test_erc20_deposit_refund.go Updated TestERC20DepositAndCallRefund to use different account address retrieval method and operational policy name for broadcasting the transaction.
e2e/e2etests/test_eth_deposit_liquidity_cap.go Updated TestDepositEtherLiquidityCap to use different account address retrieval method and operational policy name for broadcasting transactions.
e2e/e2etests/test_migrate_chain_support.go Updated TestMigrateChainSupport to use different account address retrieval method and operational policy name for various transaction broadcasts related to chain support.
e2e/e2etests/test_pause_zrc20.go Updated account address retrieval method and policy name used for broadcasting transactions related to pausing and unpausing ZRC20 tokens in TestPauseZRC20.
e2e/e2etests/test_rate_limiter.go Updated variable assignment from utils.FungibleAdminName to utils.OperationalPolicyName in setupRateLimiterFlags function.
e2e/e2etests/test_update_bytecode_connector.go Updated TestUpdateBytecodeConnector to use different account address retrieval method and updated broadcast transaction parameters.
e2e/e2etests/test_update_bytecode_zrc20.go Updated TestUpdateBytecodeZRC20 to use different account address retrieval method and updated broadcast transaction parameters.
e2e/runner/setup_zeta.go Replaced references to FungibleAdminName with OperationalPolicyName in method calls within E2ERunner struct affecting system contract deployment and other operations.
e2e/txserver/zeta_tx_server.go Added MustGetAccountAddressFromName method to ZetaTxServer struct for retrieving account address from a given name.
e2e/utils/zetacore.go Renamed FungibleAdminName to EmergencyPolicyName, AdminPolicyName, and OperationalPolicyName, introducing new names for different policies.

Sequence Diagram(s)

No sequence diagrams are necessary as the changes involve refactoring existing functionality to use different accounts, without altering the control flow or introducing new features.

Assessment against linked issues

Objective (Issue #2447) Addressed Explanation
Add separate admin accounts for each policy
Refactor e2e tests to use separate policy accounts

Poem

In the land of code and test,
New accounts for policies, the best.
Emergency, Operational, Admin too,
Each with roles and tasks to do.
Testing strong and clear, they stand,
In ZetaChain's vast software land.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kingpinXD kingpinXD changed the title Separate admin addresses refactor: separate policy addresses in e2e tests Jul 10, 2024
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 15.00000% with 17 lines in your changes missing coverage. Please review.

Project coverage is 68.99%. Comparing base (d0db41c) to head (982285d).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2459      +/-   ##
===========================================
- Coverage    69.05%   68.99%   -0.06%     
===========================================
  Files          308      308              
  Lines        19192    19209      +17     
===========================================
+ Hits         13253    13254       +1     
- Misses        5264     5278      +14     
- Partials       675      677       +2     
Files Coverage Δ
e2e/config/config.go 26.92% <15.00%> (-2.17%) ⬇️

@kingpinXD kingpinXD changed the title refactor: separate policy addresses in e2e tests refactor: add separate accounts for each policy in e2e tests Jul 10, 2024
@kingpinXD kingpinXD marked this pull request as ready for review July 10, 2024 19:33
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Outside diff range, codebase verification and nitpick comments (1)
e2e/txserver/zeta_tx_server.go (1)

156-157: Add space after the period in the comment.

Ensure there is a space after the period in the comment for better readability.

- // MustGetAccountAddressFromName returns the account address from the given name.It panics on error
+ // MustGetAccountAddressFromName returns the account address from the given name. It panics on error
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7e1dd53 and 71157c9.

Files selected for processing (15)
  • changelog.md (1 hunks)
  • cmd/zetae2e/config/localnet.yml (1 hunks)
  • cmd/zetae2e/local/local.go (1 hunks)
  • contrib/localnet/scripts/start-zetacored.sh (2 hunks)
  • e2e/config/config.go (5 hunks)
  • e2e/e2etests/test_erc20_deposit_refund.go (1 hunks)
  • e2e/e2etests/test_eth_deposit_liquidity_cap.go (2 hunks)
  • e2e/e2etests/test_migrate_chain_support.go (4 hunks)
  • e2e/e2etests/test_pause_zrc20.go (2 hunks)
  • e2e/e2etests/test_rate_limiter.go (1 hunks)
  • e2e/e2etests/test_update_bytecode_connector.go (1 hunks)
  • e2e/e2etests/test_update_bytecode_zrc20.go (1 hunks)
  • e2e/runner/setup_zeta.go (2 hunks)
  • e2e/txserver/zeta_tx_server.go (1 hunks)
  • e2e/utils/zetacore.go (1 hunks)
Additional context used
Path-based instructions (13)
e2e/e2etests/test_update_bytecode_connector.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_eth_deposit_liquidity_cap.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_update_bytecode_zrc20.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_pause_zrc20.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_erc20_deposit_refund.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/utils/zetacore.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/runner/setup_zeta.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_rate_limiter.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_migrate_chain_support.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/config/config.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetae2e/local/local.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/txserver/zeta_tx_server.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

contrib/localnet/scripts/start-zetacored.sh (1)

Pattern **/*.sh: Review the shell scripts, point out issues relative to security, performance, and maintainability.

Gitleaks
cmd/zetae2e/config/localnet.yml

39-39: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


43-43: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


47-47: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

GitHub Check: codecov/patch
e2e/config/config.go

[warning] 204-208: e2e/config/config.go#L204-L208
Added lines #L204 - L208 were not covered by tests


[warning] 232-232: e2e/config/config.go#L232
Added line #L232 was not covered by tests


[warning] 236-239: e2e/config/config.go#L236-L239
Added lines #L236 - L239 were not covered by tests


[warning] 241-243: e2e/config/config.go#L241-L243
Added lines #L241 - L243 were not covered by tests


[warning] 287-287: e2e/config/config.go#L287
Added line #L287 was not covered by tests


[warning] 291-291: e2e/config/config.go#L291
Added line #L291 was not covered by tests

Additional comments not posted (22)
e2e/e2etests/test_update_bytecode_connector.go (1)

49-53: Ensure correct usage of new policy accounts.

The function MustGetAccountAddressFromName is used correctly to get the AdminPolicyName account address, and the BroadcastTx function is called with the correct policy name. Ensure all instances where the FungibleAdminName was used are updated similarly.

e2e/e2etests/test_pause_zrc20.go (2)

38-41: LGTM!

The change to use the EmergencyPolicyName for pausing the ZRC20 token is consistent with the PR objectives.


109-112: LGTM!

The change to use the OperationalPolicyName for unpausing the ZRC20 token is consistent with the PR objectives.

e2e/e2etests/test_erc20_deposit_refund.go (1)

39-45: LGTM!

The change to use the OperationalPolicyName for refunding the aborted CCTX is consistent with the PR objectives.

e2e/utils/zetacore.go (1)

19-21: LGTM!

The introduction of new constants for EmergencyPolicyName, AdminPolicyName, and OperationalPolicyName is consistent with the PR objectives.

e2e/runner/setup_zeta.go (2)

78-78: LGTM!

The change to use the OperationalPolicyName for deploying system contracts and ZRC20 tokens on ZEVM is consistent with the PR objectives.


212-219: LGTM!

The change to use the OperationalPolicyName for enabling header verification and funding the emissions pool is consistent with the PR objectives.

e2e/e2etests/test_rate_limiter.go (1)

174-174: LGTM!

The change to use the new OperationalPolicyName account is correct.

e2e/e2etests/test_migrate_chain_support.go (5)

62-63: LGTM!

The change to use the new OperationalPolicyName account is correct.


70-81: LGTM!

The change to use the new OperationalPolicyName account is correct.


99-100: LGTM!

The change to use the new OperationalPolicyName account is correct.


110-111: LGTM!

The change to use the new OperationalPolicyName account is correct.


159-160: LGTM!

The change to use the new OperationalPolicyName account is correct.

e2e/config/config.go (3)

46-46: LGTM!

The addition of PolicyAccounts to the Config struct is correct.


61-68: LGTM!

The removal of UserFungibleAdmin from AdditionalAccounts is correct.


70-73: LGTM!

The addition of PolicyAccounts struct is correct.

cmd/zetae2e/local/local.go (1)

129-134: LGTM!

The change to use the new policy account names is correct.

e2e/txserver/zeta_tx_server.go (1)

158-168: Ensure proper usage of panic in MustGetAccountAddressFromName.

Using panic is generally discouraged in non-test code due to its impact on program stability. However, since this function is intended for test usage only, it is acceptable here. Ensure this function is not used in production code.

Ensure the function is used only in test files.

Verification successful

Ensure MustGetAccountAddressFromName is used only in test files.

The function MustGetAccountAddressFromName is used in the following files:

  • e2e/e2etests/test_update_bytecode_connector.go
  • e2e/e2etests/test_migrate_chain_support.go
  • e2e/e2etests/test_eth_deposit_liquidity_cap.go
  • e2e/e2etests/test_erc20_deposit_refund.go
  • e2e/e2etests/test_pause_zrc20.go
  • e2e/e2etests/test_update_bytecode_zrc20.go

These files are located in the e2e/e2etests/ directory, which suggests they are test files. The function appears to be used only in test files, which aligns with the intended usage.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Ensure `MustGetAccountAddressFromName` is used only in test files.
# Test: Search for the function usage. Expect: Only occurances in test files.
rg --type go 'MustGetAccountAddressFromName'

Length of output: 1700

changelog.md (1)

79-79: LGTM! Addition of separate accounts for each policy in E2E tests.

The entry is consistent with the changelog's style and accurately describes the change.

e2e/e2etests/test_eth_deposit_liquidity_cap.go (2)

28-32: Review: Use OperationalPolicyName for account retrieval and broadcasting

The new account retrieval method MustGetAccountAddressFromName(utils.OperationalPolicyName) and the corresponding policy name are used correctly for broadcasting the transaction.


72-77: Review: Use OperationalPolicyName for setting liquidity cap

The correct account retrieval method and policy name are used for setting the liquidity cap.

e2e/e2etests/test_update_bytecode_zrc20.go (1)

71-75: Review: Use AdminPolicyName for updating contract bytecode

The new account retrieval method MustGetAccountAddressFromName(utils.AdminPolicyName) and the corresponding policy name are used correctly for updating the contract bytecode.

e2e/e2etests/test_rate_limiter.go Show resolved Hide resolved
e2e/config/config.go Show resolved Hide resolved
e2e/config/config.go Show resolved Hide resolved
e2e/config/config.go Show resolved Hide resolved
contrib/localnet/scripts/start-zetacored.sh Show resolved Hide resolved
contrib/localnet/scripts/start-zetacored.sh Show resolved Hide resolved
contrib/localnet/scripts/start-zetacored.sh Show resolved Hide resolved
cmd/zetae2e/config/localnet.yml Show resolved Hide resolved
@lumtis lumtis added the ADMIN_TESTS Run make start-admin-tests label Jul 11, 2024
@lumtis
Copy link
Member

lumtis commented Jul 11, 2024

Need #2463 to be merged to fully test the functionality

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 71157c9 and 982285d.

Files selected for processing (2)
  • changelog.md (1 hunks)
  • e2e/e2etests/test_rate_limiter.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • changelog.md
Additional context used
Path-based instructions (1)
e2e/e2etests/test_rate_limiter.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Additional comments not posted (1)
e2e/e2etests/test_rate_limiter.go (1)

170-174: Use MustGetAccountAddressFromName for better error handling.

Instead of checking for errors manually, use MustGetAccountAddressFromName to simplify the code and ensure it panics on error, which is appropriate for test setup code.

- adminAddr, err := r.ZetaTxServer.GetAccountAddressFromName(utils.OperationalPolicyName)
- if err != nil {
-     return err
- }
+ adminAddr := r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName)

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

e2e/config/config.go Show resolved Hide resolved
@kingpinXD kingpinXD enabled auto-merge July 12, 2024 15:26
@kingpinXD kingpinXD added this pull request to the merge queue Jul 12, 2024
Merged via the queue into develop with commit 98a408f Jul 12, 2024
29 of 30 checks passed
@kingpinXD kingpinXD deleted the separate-admin-addresses branch July 12, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADMIN_TESTS Run make start-admin-tests breaking:cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add separate admin accounts for each policy
3 participants